package jfreechart.tsp.arithmetic;


//城市:在遗传算法中相当于一个基因
public class City {
    public int idx;//城市索引下标,用于相关二维数组(邻接矩阵,信息素矩阵)处理
    int x;
    int y;

    public City() {
        this.x = (int) (Math.random() * 200);
        this.y = (int) (Math.random() * 200);
    }

    public City(int idx, int x, int y) {
        this.idx = idx;
        this.x = x;
        this.y = y;
    }

    public int getIdx() {
        return idx;
    }

    public void setIdx(int idx) {
        this.idx = idx;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof City)) {
            return false;
        }
        City other = (City) obj;
        if (this.x == other.x && this.y == other.y) {
            return true;
        }
        return false;
    }

    //城市的欧几里德距离
    public double distTo(City city) {
        return Math.sqrt(Math.pow(this.x - city.getX(), 2) + Math.pow(this.y - city.getY(), 2));
    }

    @Override
    public String toString() {
        return "(" + x + "," + y + ")";
    }
}
